package com.ecoolex.hotel.saas.core.manager;

import com.ecoolex.hotel.saas.core.dao.PresaleCouponOrderOperateRecordDAO;
import com.ecoolex.hotel.saas.entity.PresaleCouponOrderOperateRecord;
import com.ecoolex.hotel.saas.entity.PresaleCouponOrderOperateRecord.Column;
import com.ecoolex.hotel.saas.entity.PresaleCouponOrderOperateRecordExample;
import com.ecoolex.hotel.saas.entity.PresaleCouponOrderOperateRecordExample.Criteria;

import java.time.Instant;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PresaleCouponOrderOperateRecordManager {
	
    @Autowired
    private PresaleCouponOrderOperateRecordDAO dao;
    
    public void create(Integer orderId, Integer type, String remark,String couponCode, String createUser) {
    	PresaleCouponOrderOperateRecord record = new PresaleCouponOrderOperateRecord();
    	record.setOrderId(orderId);
    	record.setCouponCode(couponCode);
    	record.setType(type);
    	record.setRemark(remark);
    	record.setDeleted(PresaleCouponOrderOperateRecord.NOT_DELETED);
    	record.setCreateUser(createUser);
    	record.setCreateTime(Date.from(Instant.now()));
    	record.setUpdateUser(createUser);
    	record.setUpdateTime(Date.from(Instant.now()));
    	dao.insert(record);
    }
    
    public List<PresaleCouponOrderOperateRecord> operateRecordList(Integer orderId) {
    	PresaleCouponOrderOperateRecordExample example = new PresaleCouponOrderOperateRecordExample();
    	Criteria criteria = example.createCriteria();
    	criteria.andOrderIdEqualTo(orderId).andDeletedEqualTo(PresaleCouponOrderOperateRecord.NOT_DELETED);
    	example.orderBy(Column.createTime.desc());
		return dao.selectByExample(example);
	}
}